define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'basedata/roomdatas/index',
                    add_url: 'basedata/roomdatas/add/ids/{ids}',
                    edit_url: 'basedata/roomdatas/edit',
                    del_url: 'basedata/roomdatas/del',
                    multi_url: 'basedata/roomdatas/multi',
                    table: 'roomdatas',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                singleSelect: true, //是否启用单选
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'weigh',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'rdname', title: __('Rdname')},
                        /*{field: 'category_id', title: __('Category_id')},*/
                        {field: 'category_name', title:__('Category_id'),operate: false, formatter: Table.api.formatter.label},
                        {field: 'pid', title: __('Pid')},
                        {field: 'index', title: __('Index')},
                        {field: 'ctype', title: __('Ctype'), visible:false, searchList: {"null":__('ctype null'),"radio":__('ctype radio'),"checkbox":__('ctype checkbox')}},
                        {field: 'ctype_text', title: __('Ctype'), operate:false},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'status', title: __('Status'), visible:false, searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2')}},
                        {field: 'status_text', title: __('Status'), operate:false},
                        {field: 'weigh', title: __('Weigh')},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                        /*{field: 'append-operate', title: __('append-operate'), table:table, 
                            buttons: [
                                {name: 'detail', text: '弹窗', title: '弹窗标题', icon: 'fa fa-list', classname: 'btn btn-xs btn-primary btn-dialog', url: 'page/detail', callback:function(data){}},
                                {name: 'detail', text: 'Ajax', title: 'Ajax标题', icon: 'fa fa-flash', classname: 'btn btn-xs btn-success btn-ajax', url: 'page/detail', success:function(data, ret){}, error:function(){}},
                                {name: 'detail', text: '选项卡', title: '选项卡标题', icon: 'fa fa-flash', classname: 'btn btn-xs btn-info btn-addtabs', url: 'page/detail'}
                            ],operate: false, formatter: Table.api.formatter.buttons
                        }*/
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});